package cn.cvs.controller;

import cn.cvs.pojo.Rent;
import cn.cvs.service.RentService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping(value = "/rent")
public class RentController {

    private Logger logger = Logger.getLogger(RentController.class);
    @Autowired
    private RentService rentService;

    @RequestMapping(value ="/list")
    public String login(Model model,String userName){

        List<Rent> rent = rentService.list(userName);
        model.addAttribute("rent",rent);
        model.addAttribute("userName",userName);
        return "list";
    }


    //跳转到添加用户页面
    @RequestMapping(value ="toAdd")
    public String toAdd(){
        return "add";
    }
    @RequestMapping(value ="/add")
    public String add(Rent rent){

        int result=rentService.add(rent);
        if (result>0){
            return "redirect:/index";
        }
        return "add";
    }

    @RequestMapping(value ="/del")
    public String del(Integer id){
        int result=rentService.del(id);
        if (result>0){
            return "redirect:/index";
        }

        return "list";
    }





}
